//
//  ZSBaseViewController.swift
//  ZSWeibo
//
//  Created by zsj1992 on 16/4/8.
//  Copyright © 2016年 ichange. All rights reserved.
//

import UIKit

class ZSBaseViewController: UITableViewController,ZSVisitViewDelegate {
    
//    var userLogin:Bool = ZSUserAccountViewModel.sharedUserViewModel.userAccount != nil
    var userViewModel = ZSUserAccountViewModel.sharedUserViewModel

    //基类提供一个访客视图的属性,如果是未登录的状态,这个访客视图是有值的,不为nil,已经登录的状态下这个访客视图值为nil,也不影响,各个子控件就调用自身父类的loadView方法
    var visitorView:ZSVisitView?

    override func viewDidLoad() {
       
        super.viewDidLoad()

        self.navigationItem.leftBarButtonItem = UIBarButtonItem.creatItem(nil, target: self, action: "btnLoginDidClick", title: "登录")
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem.creatItem(nil, target: self, action: "btnRegisterDidClick", title: "注册")
    }

    
//    override func viewWillAppear(animated: Bool) {
//      
//        let view1 = ZSWelcomeViewController().view
//        
//        setValue(view1, forKeyPath: "view")
//        
//    }
    
    override func loadView() {
        
//        userViewModel.userLogin ? super.loadView():customLoadView()
//      print(UIApplication.sharedApplication().keyWindow?.rootViewController)
        
    userViewModel.userLogin ? super.loadView():customLoadView()

        
    }
    
    
    func customLoadView(){
        
        visitorView  = ZSVisitView()
        
        visitorView?.delegate = self
        
        self.view = visitorView
    }
    
    
    func btnLoginDidClick() {
      
        print("控制器弹出登录界面")
        
        let wvv = ZSOAuthController()

        let wv = ZSNavicationController(rootViewController: wvv)
     
        presentViewController(wv, animated: true, completion: nil)
        
        
        
    }
    func btnRegisterDidClick() {
        print("弹出注册界面")
    }









}



